
let {Service} = require('egg');
class BaseService extends Service {
  async select(pageNum=1,pageSize=3,where={}){
      let {app} = this;
      let list =  await app.mysql.select(this.model,{
        where,
        orders:[['id','asc']],//指定排序字段和排序的顺序
        offset:(pageNum-1)*pageSize,
        limit:pageSize
      });
      let total = await app.mysql.count(this.model,where);
      return {list,total};
  }
  async insert(entity){
    let {app} = this;
    let result =  await app.mysql.insert(this.model,entity);
    return result.affectedRows;
  }
  async update(entity){
    let {app} = this;
    let result = await app.mysql.update(this.model,entity);
    return result.affectedRows;
  }
  async destroy(ids){
    let {app} = this;
    console.log('ids',ids);
    let result =await app.mysql.delete(this.model,{id:ids});// id in (1,2,3)
    return result.affectedRows;
  }
}
module.exports = BaseService;